package org.hxzon.tapestry5.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractConditional;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.util.OgnlUtil;

public class OgnlIf extends AbstractConditional {

    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String test;

    @Parameter
    private Object root;

    @Inject
    private ComponentResources componentResources;

    @Override
    protected boolean test() {
        Object value = OgnlUtil.getValue(root != null ? root : componentResources.getContainer(), test);
        return Boolean.valueOf(value.toString());
    }

}
